package com.fengye.cloud.reactive.service.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 对 Eureka 进行测试
 * @author sky
 * @date 2021年06月02日 10:18 上午
 */
@Service
public class TestEurekaService {

    @Autowired
    private DiscoveryClient discoveryClient;

    /**
     * 获取所有服务列表信息
     * @return 服务列表信息
     */
    public List<String> getEurekaService() {
        List<String> services = new ArrayList<>();
        discoveryClient.getServices().forEach(serviceName -> {
            discoveryClient.getInstances(serviceName).forEach(instance -> {
                services.add(String.format("%s,%s", serviceName, instance.getUri()));
            });
        });
        return services;
    }
}
